package abq2.jic.jic.plugin.operate.mobie;

import kd.bos.form.MobileFormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.control.Control;
import kd.bos.form.control.IFrame;
import kd.bos.form.plugin.AbstractMobFormPlugin;

import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;

public class BookMobHomePlugin extends AbstractMobFormPlugin {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        IFrame iframe = this.getView().getControl("abq2_iframeap");
        String mainurl = "http://127.0.0.1:8881/ierp";
        mainurl = mainurl + "/mobile.html?form=abq2_zz1";
        iframe.setSrc(mainurl);


        MobileFormShowParameter showParameter = new MobileFormShowParameter();
        showParameter.setFormId("abq2_zz1");
        showParameter.getOpenStyle().setTargetKey("abq2_flex_container");
        showParameter.getOpenStyle().setShowType(ShowType.InContainer);
        getView().showForm(showParameter);
    }

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        addClickListeners("abq2_home", "abq2_my");
    }

    @Override
    public void click(EventObject evt) {
        super.click(evt);
        if (evt.getSource() instanceof Control) {
            switch ( ((Control)evt.getSource()).getKey() ) {
                case "abq2_home": {

                    IFrame iframe = this.getView().getControl("abq2_iframeap");
                    String mainurl = "http://127.0.0.1:8881/ierp";
                    mainurl = mainurl + "/mobile.html?form=abq2_zz1";
                    iframe.setSrc(mainurl);

                    MobileFormShowParameter showParameter = new MobileFormShowParameter();
                    showParameter.setFormId("abq2_zz1");
                    showParameter.getOpenStyle().setTargetKey("abq2_flex_container");
                    showParameter.getOpenStyle().setShowType(ShowType.InContainer);
                    getView().showForm(showParameter);

                    Map fieldMap = new HashMap();
                    fieldMap.put("imageKey", "/icons/mobile/tab_bar/icon_homepage_64_64.png");
                    getView().updateControlMetadata("abq2_home", fieldMap);
                    Map fieldMap2 = new HashMap();
                    fieldMap2.put("imageKey", "/icons/mobile/tab_bar/icon_my(x)_64_64.png");
                    getView().updateControlMetadata("abq2_my", fieldMap2);
                }
                    break;
                case "abq2_my": {

                    MobileFormShowParameter showParameter = new MobileFormShowParameter();
                    showParameter.setFormId("abq2_bookmy");
                    showParameter.getOpenStyle().setTargetKey("abq2_flex_container");
                    showParameter.getOpenStyle().setShowType(ShowType.InContainer);
                    getView().showForm(showParameter);

                    IFrame iframe = this.getView().getControl("abq2_iframeap");
                    String mainurl = "http://127.0.0.1:8881/ierp";
                    mainurl = mainurl + "/mobile.html?form=abq2_bookmy";
                    iframe.setSrc(mainurl);

                    Map fieldMap = new HashMap();
                    fieldMap.put("imageKey", "/icons/mobile/tab_bar/icon_homepage(x)_64_64.png");
                    getView().updateControlMetadata("abq2_home", fieldMap);
                    Map fieldMap2 = new HashMap();
                    fieldMap2.put("imageKey", "/icons/mobile/tab_bar/icon_my_64_64.png");
                    getView().updateControlMetadata("abq2_my", fieldMap2);
                }
                    break;
            }
        }
    }



}
